package com.panda.game.xls.action;

import com.panda.game.xls.component.MyJTextField;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class OpenFileAction implements ActionListener {

    private MyJTextField jtf;

    public OpenFileAction() {

    }

    public OpenFileAction(MyJTextField jtf) {
        this.jtf = jtf;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //硬编码，之后调整
        JFileChooser fc = new JFileChooser("D:\\");
        int val = fc.showOpenDialog(null);    //文件打开对话框
        if (val == fc.APPROVE_OPTION) {
            //正常选择文件
            jtf.setText(fc.getSelectedFile().toString());
        } else {
            //未正常选择文件，如选择取消按钮
            jtf.setText("未选择文件");
        }
    }

}
